﻿Option:
	If WinExist("ahk_id" HGui3){
		WinActivate, ahk_id%HGui3%
		Return
	}
	OnMessage(0x200, "WM_MOUSEMOVE")
	Gui, 3:Destroy
	DB.GetTable("SELECT name FROM sqlite_master WHERE type='table' AND NOT instr(tbl_name,'@') AND tbl_name NOT IN ('symbol','customs','functions','hotstrings','pinyin','hebing','sqlite_sequence')",TableInfo)
	xingmaleitable:=""
	Loop % TableInfo.RowCount
		xingmaleitable .= "|" TableInfo.Rows[A_Index,1]
	xingmaleitable:=xingmaleitable?xingmaleitable:"|"
	Gui, 3:-DPIScale +hwndHGui3
	Gui, 3:Default
	Gui, 3:Margin, 12, 12
	Gui, 3:Font, s10 bold, %GUIFont%
	Gui, 3:Add, Tab3, xp yp+15 gswitchtab AltSubmit, 常规|界面|控制|关于
	Gui, 3:Tab, 1
	Gui, 3:Font, s10 norm, %GUIFont%
	Gui, 3:Add, CheckBox, xm+15 ym+45 Section gStarting vStartingup Checked%Startingup%, 开机启动
	Gui, 3:Add, CheckBox, x+20 yp gini_Settings vAutoupdatefg Checked%Autoupdatefg%, 自动更新
	Gui, 3:Add, CheckBox, x+20 yp grunasadmin vAdminfg Checked%Adminfg%, 管理员权限
	Gui, 3:Add, CheckBox, x+20 yp gini_Settings vMemoryDB Checked%MemoryDB%, 内存数据库
	Gui, 3:Add, CheckBox, xs y+10 gini_Settings vSendFromClip Checked%SendFromClip%, 剪贴板上屏
	Gui, 3:Add, Text, x+10 yp Right, 发送延时：
	Gui, 3:Add, DropDownList, x+0 yp-5 hp-2 w50 r10 gini_Settings vSendDelay, 0|1|2|3|4|5|6|7|8|9|10
	Gui, 3:Add, Text, x+20 yp+5 Right, Debug：
	Gui, 3:Add, DropDownList, x+0 yp-5 hp-2 w90 r5 gini_Settings vDebugLevel AltSubmit Choose%DebugLevel%, log|DebugView|MsgBox|测速|禁用
	GuiControlGet, tempP, 3:Pos, DebugLevel
	tvar:=tempPx+tempPw-30
	GuiControlGet, tempP, 3:Pos, MemoryDB
	tvar:=Max(tempPx+tempPw-30,tvar)
	Gui, 3:Add, GroupBox, xm+15 yp+35 w%tvar% h100, 辅助功能
	Gui, 3:Add, CheckBox, xp+20 yp+25 Section gini_Settings vWordfrequency Checked%Wordfrequency%, 动态调频
	Gui, 3:Add, CheckBox, x++15 yp gini_Settings vfixedword Checked%fixedword%, 单字固定
	Gui, 3:Add, Checkbox, x++15 yp gini_Settings vLearning Checked%Learning%, 自学习　
	Gui, 3:Add, CheckBox, x++15 yp gini_Settings vImagine Checked%Imagine%, 联想　　
	Gui, 3:Add, CheckBox, xs y+10 gini_Settings vbddp Checked%bddp%, 标点上屏
	Gui, 3:Add, CheckBox, x++15 yp gini_Settings vMouseCross Checked%MouseCross%, 鼠标划词
	Gui, 3:Add, CheckBox, x++15 yp gini_Settings vSuperrun Checked%Superrun%, 超级命令
	Gui, 3:Add, CheckBox, x++15 yp gini_Settings vMagicstring Checked%Magicstring%, 魔法字符串
	GuiControlGet, tempP, 3:Pos, Superrun
	GuiControl, 3:Move, 辅助功能, % "h" tempPh*2+50
	Gui, 3:Add, GroupBox, xm+15 y+20 w%tvar% h100, 默认模式
	Gui, 3:Add, Checkbox, xp+20 yp+25 gini_Settings vDifferent Checked%Different%, 允许每个应用使用不同的输入模式
	Gui, 3:Add, Text, xm+35 y+10, 默认输入模式：
	Gui, 3:Add, DropDownList, x+0 yp-5 w80 gini_Settings vIMEmode AltSubmit Choose%IMEmode%, 英文|中文
	Gui, 3:Add, Button, x+40 yp-1 hp+2 gappmanager, 应用管理
	GuiControlGet, tempP, 3:Pos, Different
	GuiControl, 3:Move, 默认模式, % "h" tempPh*2+50
	Gui, 3:Add, GroupBox, xm+15 y+15 w%tvar% h70, 输入方案
	Gui, 3:Add, Radio, xp+20 yp+25 gshurulei AltSubmit, 拼音类
	Gui, 3:Add, Radio, x+20 yp gshurulei AltSubmit, 形码类
	Gui, 3:Add, DropDownList, x+5 yp-5 w120 gsurufangan v_Inputscheme, % Trim(pinyinlist,"|")
	Gui, 3:Add, CheckBox, x+25 yp+5 gini_Settings vTraditional Checked%Traditional%, 繁体中文
	GuiControlGet, tempP, 3:Pos, 拼音类
	GuiControl, 3:Move, 输入方案, % "h" tempPh+40
	Gui, 3:Add, GroupBox, xm+15 y+20 w%tvar% h95 Section, 输入选项
	Gui, 3:Add, Checkbox, xm+35 yp+25 gini_Settings vShowquanpin Checked%Showquanpin% Hidden, 自动扩展到全拼
	Gui, 3:Add, Checkbox, x+30 yp gini_Settings vfuzhuma Checked%fuzhuma% Hidden, 辅助码
	Gui, 3:Add, Checkbox, x+30 yp gini_Settings vchaojijp Checked%chaojijp% Hidden, 超级简拼
	Gui, 3:Add, Checkbox, xm+35 y+10 gini_Settings vSaveCloud Checked%SaveCloud% Hidden, 云结果存入词库
	Gui, 3:Add, Checkbox, x+30 yp gini_Settings vCloudInput Checked%CloudInput% Hidden, 云输入
	Gui, 3:Add, Checkbox, x+30 yp gini_Settings vdwxg Checked%dwxg% Hidden, 定位修改
	GuiControlGet, tempP, 3:Pos, SaveCloud
	GuiControl, 3:Move, 输入选项, % "h" tempPh*2+50
	Gui, 3:Add, GroupBox, xm+15 y+20 w%tvar% h90 Hidden, 模糊音设置
	Gui, 3:Add, CheckBox, xp+20 yp+25 w120 gmohuying vmhy_zh Checked%mhy_zh% Hidden, zh，z
	Gui, 3:Add, CheckBox, x+35 yp w120 gmohuying vmhy_sh Checked%mhy_sh% Hidden, sh，s
	Gui, 3:Add, CheckBox, x+35 yp w120 gmohuying vmhy_ch Checked%mhy_ch% Hidden, ch，c
	Gui, 3:Add, CheckBox, xm+35 y+10 w120 gmohuying vmhy_ang Checked%mhy_ang% Hidden, ang，an
	Gui, 3:Add, CheckBox, x+35 yp w120 gmohuying vmhy_eng Checked%mhy_eng% Hidden, eng，en
	Gui, 3:Add, CheckBox, x+35 yp w120 gmohuying vmhy_ing Checked%mhy_ing% Hidden, ing，in
	GuiControlGet, tempP, 3:Pos, mhy_ang
	GuiControl, 3:Move, 模糊音设置, % "h" tempPh*2+50
	Gui, 3:Add, CheckBox, xs+20 ys+25 gini_Settings vwumaqc Checked%wumaqc% Hidden, 误码清除
	Gui, 3:Add, CheckBox, x+20 yp gini_Settings vsimasp Checked%simasp% Hidden, 四码上屏
	Gui, 3:Add, CheckBox, x+20 yp gini_Settings vwumasp Checked%wumasp% Hidden, 五码首选上屏
	Gui, 3:Add, CheckBox, xm+35 y+10 gini_Settings vShowCode Checked%ShowCode% Hidden, 编码反查
	Gui, 3:Add, CheckBox, x+20 yp gini_Settings vzigen Checked%zigen% Hidden, 显示字根
	Gui, 3:Add, CheckBox, x+20 yp gini_Settings vpinyinhunsu Checked%pinyinhunsu% Hidden, 拼音(Shift+z)
	Gui, 3:Tab, 2
	Gui, 3:Add, GroupBox, xm+15 ym+40 w%tvar% h325, 候选窗口
	Gui, 3:Add, Text, xm+55 yp+30, 文本字体：
	Gui, 3:Font, s8
	Gui, 3:Add, DropDownList, x+0 yp w180 hp r10 gini_GuiStyle vTextFont, % ListFonts()
	Gui, 3:Font, s10
	Gui, 3:Add, Text, x+30 yp, 字号：
	Gui, 3:Add, Edit, x+0 yp-5 w50 Limit2 Number vFontSize
	Gui, 3:Add, UpDown, Range8-40, 20
	Gui, 3:Add, Text, xm+55 y+15, 符号字体：
	Gui, 3:Font, s8
	Gui, 3:Add, DropDownList, x+0 w180 hp r10 gini_GuiStyle vSymbolFont, % ListFonts()
	Gui, 3:Font, s10
	Gui, 3:Add, Checkbox, x+75 gini_GuiStyle vFontBold Checked%FontBold%, 粗体
	If (YzIni["Hidden","ColorControl"]){
		OnMessage(0x0138, "WM_CTLCOLORSTATIC")
		Gui, 3:Add, Text, xm+55 y+20, 编码颜色：
		Gui, 3:Add, Text, x+0 yp-5 w86 gsetcolor vCodeColor BackgroundTrans Border Center, % SubStr(CodeColor, -5)
		Gui, 3:Add, Text, x+40 yp+5 w100 Right, 文本颜色：
		Gui, 3:Add, Text, x+0 yp-5 w86 gsetcolor vTextColor BackgroundTrans Border Center, % SubStr(TextColor, -5)
		Gui, 3:Add, Text, xm+55 y+15, 背景颜色：
		Gui, 3:Add, Text, x+0 yp-5 w86 gsetcolor vBackgroundColor BackgroundTrans Border Center, % SubStr(BackgroundColor, -5)
		Gui, 3:Add, Text, x+40 yp+5 w100 Right, 边框颜色：
		Gui, 3:Add, Text, x+0 yp-5 w85 gsetcolor vBorderColor BackgroundTrans Border Center, % SubStr(BorderColor, -5)
	} Else {
		Gui, 3:Add, Text, xm+55 y+20, 编码颜色：
		Gui, 3:Add, Button, x+0 yp-5 w86 gsetcolor vCodeColor, % SubStr(CodeColor, -5)
		Gui, 3:Add, Text, x+40 yp+5 w100 Right, 文本颜色：
		Gui, 3:Add, Button, x+0 yp-5 w86 gsetcolor vTextColor, % SubStr(TextColor, -5)
		Gui, 3:Add, Text, xm+55 y+15, 背景颜色：
		Gui, 3:Add, Button, x+0 yp-5 w86 gsetcolor vBackgroundColor, % SubStr(BackgroundColor, -5)
		Gui, 3:Add, Text, x+40 yp+5 w100 Right, 边框颜色：
		Gui, 3:Add, Button, x+0 yp-5 w85 gsetcolor vBorderColor, % SubStr(BorderColor, -5)
		For key,value In ["CodeColor","TextColor","BackgroundColor","BorderColor"]
			SetButtonColor(value, "0x" %value%)
	}
	Gui, 3:Add, Text, xm+55 y+15, 候选项数：
	Gui, 3:Add, DropDownList, x+1 yp-5 w84 vListNum gini_GuiStyle, 3|4|5||6|7|8|9|10
	Gui, 3:Add, Text, x+20 yp+5 w120 Right, Logo缩放：
	Gui, 3:Add, Edit, x+0 yp-5 w60 Limit3 Number vLogoSize
	Gui, 3:Add, UpDown, Range10-100, 100
	Gui, 3:Add, Text, x+10 yp+5, `%
	Gui, 3:Add, Text, xm+55 y+20, 显示样式：
	Gui, 3:Add, DropDownList, x+1 yp-5 w84 vToolTipStyle gini_GuiStyle AltSubmit Choose%ToolTipStyle%, ToolTip|Gdip
	Gui, 3:Add, CheckBox, x+50 yp+5 w100 vLockedposition gini_GuiStyle Checked%Lockedposition%, 固定位置
	Gui, 3:Add, Text, xm+55 y+20, 排列方式：
	Gui, 3:Add, Radio, x+30 yp Checked vHorizontal gTextdirection, 横版
	Gui, 3:Add, Radio, x+30 yp vVertical gTextdirection, 竖版
	GuiControlGet, tempP, 3:Pos, 排列方式：
	GuiControl, 3:Move, 候选窗口, % "h" tempPy-15
	Gui, 3:Tab, 3
	Gui, 3:Add, GroupBox, xm+15 ym+40 w%tvar% h165, 输入法热键
	Gui, 3:Add, Text, xm+40 yp+35 w100 Right, 切换热键：
	Gui, 3:Add, Edit, x+0 yp-5 w100 vsrfhotkey, %Switch%
	Gui, 3:Add, Button, x+15 yp-1 gsethotkey, 设置
	Gui, 3:Add, CheckBox, x+20 yp+5 gini_Hotkey vDouble Checked%Double%, 双击切换
	Gui, 3:Add, Text, xm+40 yp+45 w100 Right, Enter键：
	Gui, 3:Add, DropDownList, x+0 yp-5 w100 AltSubmit vEnterfg gini_Hotkey Choose%Enterfg%, 清除编码|上屏编码
	Gui, 3:Add, Text, x+5 yp+5 w100 Right, Esc键：
	Gui, 3:Add, DropDownList, x+0 yp-5 w100 AltSubmit vEscfg gini_Hotkey Choose%Escfg%, 清除编码|先清后关|英文模式
	Gui, 3:Add, Text, xm+40 yp+50 w100 Right, Shift键：
	Gui, 3:Add, DropDownList, x+0 yp-5 w100 AltSubmit vShiftfg gini_Hotkey Choose%Shiftfg%, 清除编码|上屏编码|上屏编码并切换|辅助码筛选
	Gui, 3:Add, Text, x+5 yp+5 w100 Right, 翻页键：
	Gui, 3:Add, DropDownList, x+0 yp-5 w100 vfanyefg gini_Hotkey, []|-=||[],-=
	Gui, 3:Add, GroupBox, xm+15 yp+50 w%tvar% r10, 命令管理
	Gui, 3:Add, ListView, % "xm+30 yp+25 w" tvar-30 " r11 vFuncLV -ReadOnly AltSubmit gFuncLV hwndHFuncLV"
	GuiControlGet, tempP, 3:Pos, FuncLV
	GuiControl, 3:Move, 命令管理, % "h" tempPh+40
	Gui, 3:Font
	Gui, 3:Tab, 4
	Gui, 3:Add, Picture, xm+10 ym+50 w35 h-1 Icon1, Lib\yz.icl
	Gui, 3:Font, s15 Bold, %GUIFont%
	Gui, 3:Add, Text, x+5 yp+5, 影子输入法
	Gui, 3:Font, s10 norm , %GUIFont%
	Gui, 3:Add, Text, x+0 yp+7, % " (" A_PtrSize*8 "位)"
	Gui, 3:Add, Text, x+20, % "版本：" srf_default_value["Version","Version"] " (2020.02.21)"
	Gui, 3:Add, GroupBox, xm+15 y+10 w%tvar% r4, 简介
	Gui, 3:Add, Text, % "xm+35 yp+25 w" tvar-30, %Yz_Abort%
	GuiControlGet, tempP, 3:Pos, %Yz_Abort%
	GuiControl, 3:Move, 简介, % "h" tempPh+40
	Gui, 3:Add, Text, xm+10 y+25 w80 Right, 主页:
	Gui, 3:Add, Link, x+10 yp, <a href="https://www.autoahk.com/archives/15117">https://autoahk.com/archives/15117</a>
	Gui, 3:Add, Picture, xm+15 yp w20 h-1 Icon11, Lib\yz.icl
	Gui, 3:Add, Text, xm+10 y+5 w80 Right, 源代码:
	Gui, 3:Add, Link, x+10 yp, <a href="https://gitee.com/orz707/shadow">https://gitee.com/orz707/shadow</a>
	Gui, 3:Add, Text, xm+10 y+5 w80 Right, 帮助:
	Gui, 3:Add, Link, x+10 yp, <a href="https://gitee.com/orz707/shadow/wikis/`%E5`%BF`%AB`%E9`%80`%9F`%E5`%BC`%80`%E5`%A7`%8B?sort_id=1844118">https://gitee.com/orz707/shadow/wikis</a>
	Gui, 3:Add, Text, xm+10 y+5 w80 Right, QQ群:
	Gui, 3:Add, Link, x+10 yp, <a href="https://jq.qq.com/?_wv=1027&k=5mwdF5c">「影子输入法官方群」331028595</a>
	Gui, 3:Add, Picture, xm+15 y+15 w20 h-1 Icon10, Lib\yz.icl
	Gui, 3:Font, s10 Bold, %GUIFont%
	Gui, 3:Add, Text, x+10 yp, 大本营
	Gui, 3:Font, s10 norm, %GUIFont%
	Gui, 3:Add, Text, y+5, 这里有更多精美的工具和脚本.
	Gui, 3:Add, Link, y+5, <a href="https://www.autoahk.com">「AutoAHK中文网」</a>
	Gui, 3:Add, Link, y+5, <a href="https://jq.qq.com/?_wv=1027&k=5zTs1e1">「AutoHotkey中文群」348016704</a>
	Gui, 3:Add, Picture, xm+15 y+15 w20 h-1 Icon12, Lib\yz.icl
	Gui, 3:Font, s10 Bold, %GUIFont%
	Gui, 3:Add, Text, x+10 yp, 感谢
	Gui, 3:Font, s10 norm, %GUIFont%
	Gui, 3:Add, Text, % "y+5 w" tvar-60, 非常感谢大家的支持, 感谢Hello_srf、胡杨、心如止水、jeff、is1or0（大量优秀建议）、大唐（云输入）、琪C（图标）、赵小峰（词库）
	If (Inputscheme~="sp$|pinyin"){
		GuiControl, 3:, 拼音类, 1
		_Inputscheme:=pinyinec[Inputscheme]
		GuiControl, % "3:Disable" (Inputscheme="pinyin"), Showquanpin
		Loop 13
			GuiControl, 3:Show, % "Button" (A_Index+22)
		GuiControlGet, tempP, 3:Pos, 模糊音设置
	} Else {
		GuiControl, 3:, 形码类, 1
		GuiControl, 3:, _Inputscheme, %xingmaleitable%
		_Inputscheme:=Inputscheme
		Loop 6
			GuiControl, 3:Show, % "Button" (A_Index+35)
		GuiControl, 3:Text, Imagine, 逐码提示
		GuiControl, 3:Text, Learning, 引导学习
		GuiControlGet, tempP, 3:Pos, 输入选项
	}
	GuiControl, 3:Move, SysTabControl321, % "h" tempPy+tempPh
	For Value,Key In ["_Inputscheme","SendDelay","TextFont","SymbolFont","ListNum","fanyefg"]
		GuiControl, 3:ChooseString, %Key%, % StrDeref(%Key%)
	; GuiControl, 3:, ShowCode, % YzIni["Settings", "ShowCode"]
	GuiControl, 3:Text, FontSize, %FontSize%
	GuiControl, 3:Text, LogoSize, %LogoSize%
	GuiControl, 3:, %Textdirection%, 1
	SendMessage, 0x1501, 1, "Enter Hotkey Name", Edit3, ahk_id%HGui3%
	; GuiControl, 3:Text, srfhotkey, %Switch%
	GuiControl, 3:, Double, % YzIni["Hotkey","Double"]
	GuiControl, 3:Enable%Different%, IMEmode
	GuiControl, 3:Enable%pinyinhunsu%, ShowCode
	GuiControl, 3:Enable%Wordfrequency%, fixedword
	GuiControl, 3:-ReDraw, FuncLV
	LV_InsertCol(1, "75", "命令名")
	LV_InsertCol(2, "110", "自定义命令名")
	LV_InsertCol(3, "500", "说明(s选择的文本，c剪切板中的文本)")
	For Key, Value in srf_Default_Func
		LV_Add("", Value[1], srf_Custom_Func[Value[1]], Value[2])
	LV_ModifyCol(3, "AutoHdr")
	LV_ModifyCol(1, "Sort")
	GuiControl, 3:+ReDraw, FuncLV
	ICELV2:=New LV_InCellEdit(HFuncLV, True, True)
	ICELV2.SetColumns(2)
	ICELV2.OnMessage()
	Gui, 3:Show, AutoSize, 影子输入法 选项
	GuiControl, 3:+gini_GuiStyle, FontSize
	GuiControl, 3:+gini_GuiStyle, LogoSize
Return

appmanager:
	Gui, 3:Hide
	Gui, app:Destroy
	Gui, app:+AlwaysOnTop -MinimizeBox
	Gui, app:Font, s12, %GUIFont%
	Gui, app:Add, Radio, xm yp+10 Checked1, 进程名
	Gui, app:Add, Radio, x+40, 类名
	Gui, app:Add, Edit, xm y+10 -Multi r1 w160
	Gui, app:Add, Button, x+10 yp-2 gaddapp, 添加
	Gui, app:Add, ListView, r10 x10 w280 Grid Hwndtvar, 进程名或类名|输入状态
	DllCall("UxTheme.dll\SetWindowTheme", "Ptr", tvar, "Str", "Explorer", "Ptr", 0)
	Gui, app:Default
	LV_ModifyCol(1,160), LV_ModifyCol(2,80)
	Hotkey, IfWinExist, Alt+左键识别窗口 ahk_pid%yzPID%
	Hotkey, !LButton, clicklbutton, On
	Hotkey, If
	Hotkey, IfWinActive, Alt+左键识别窗口 ahk_pid%yzPID%
	Hotkey, !c, 中文, On
	Hotkey, !d, 剪贴板, On
	Hotkey, !e, 英文, On
	Hotkey, $Del, 删除, On
	Hotkey, Enter, addapp, On
	Hotkey, If
	GuiControl, app:-ReDraw, SysListView321
	For Value,Key In ["ClipWindows","IMECnWindows","IMEEnWindows"]
		Loop, Parse, %key%, `,
			LV_Add("",A_LoopField,Value=1?"剪贴板":Value=2?"中文":"英文")
	GuiControl, app:+ReDraw, SysListView321
	Gui, app:Show, , Alt+左键识别窗口
Return

FuncLV:
	If (A_GuiEvent == "F")&&(ICELV2["Changed"]){
		If (srf_func_hk[LTrim(ICELV2.ItemText,"&")]){
			Hotkey If, srf_mode
			Try Hotkey, % LTrim(ICELV2.ItemText,"&"), Off
			Hotkey If
			Try Hotkey, % LTrim(ICELV2.ItemText,"&"), Off
		}
		ICELV2.Remove("Changed"), tarr:=[]
		Loop % LV_GetCount(){
			LV_GetText(tvar, A_Index), LV_GetText(CustomFuncName, A_Index, 2)
			If CustomFuncName
				tarr[tvar]:=CustomFuncName
		}
		YzIni["Func","CustomFuncName"]:=JSON.Dump(tarr), srf_Custom_Func:=tarr, tarr:=[]
		Gosub Registrationfuncandlabel
	}
Return

appGuiContextMenu:
	If LV_GetNext()
		Menu, appContextMenu, Show, % A_GuiX*A_ScreenDPI/96, % A_GuiY*A_ScreenDPI/96
Return
剪贴板:
中文:
英文:
删除:
	Gui, app:Default
	ControlGetFocus, tvar
	If (tvar!="SysListView321"&&A_ThisHotkey="$Del"){
		Send {Del}
		Return
	}
	GuiControl, app:-ReDraw, SysListView321
	tvar:=0
	If (A_ThisLabel="删除"){
		delrows:=[]
		While tvar:=LV_GetNext(tvar)
			delrows.Push(tvar)
		Loop % delrowsnum:=delrows.Length()
			LV_Delete(delrows[delrowsnum+1-A_Index])
	} Else
		While tvar:=LV_GetNext(tvar)
			LV_Modify(tvar, "Col2", A_ThisLabel)
	GuiControl, app:+ReDraw, SysListView321
Return
addapp(){
	Gui, app:Default
	GuiControlGet, jccl,, Edit1
	If (jccl="")
		Return
	GuiControl, app:-ReDraw, SysListView321
	Loop % LV_GetCount()
		LV_Modify(A_Index, "-Select -Focus")
	Loop % LV_GetCount(){
		LV_GetText(t, row:=A_Index)
		If (t=jccl)
			Break
	}
	If (t=jccl)
		LV_Modify(row, "Select Focus Vis")
	Else
		LV_Add("Select Focus Vis",jccl,"")
	ControlFocus, SysListView321
	GuiControl, app:+ReDraw, SysListView321
}
clicklbutton(){
	Gui, app:Default
	GuiControlGet, jccl,, Button1
	MouseGetPos, , , moupos
	If jccl
		WinGet, pos, ProcessName, ahk_id%moupos%
	Else
		WinGetClass, pos, ahk_id%moupos%
	GuiControl, app:, Edit1, %pos%
}
appGuiClose:
appGuiEscape:
	IMECnWindows:=IMEEnWindows:=ClipWindows:=""
	Loop % LV_GetCount(){
		LV_GetText(key, A_Index, 2), LV_GetText(value, A_Index, 1)
		If (key="中文")
			IMECnWindows .= "," value
		Else If (key="英文")
			IMEEnWindows .= "," value
		Else
			ClipWindows .= "," value
	}
	For Value,Key In ["ClipWindows","IMECnWindows","IMEEnWindows"]
		YzIni["Settings",key]:=%key%:=LTrim(%key%,",")
	Gui, app:Destroy
	Gui, 3:Show
Return

3GuiClose:
	3GuiEscape:
	ICELV2:="", YzIni.Save()
	If (YzIni["Hidden","ColorControl"])
		OnMessage(0x0138, ""), WM_CTLCOLORSTATIC(0,0,0,0)
	If !WinExist("ahk_id" HGui97)
		OnMessage(0x200, "")
	ToolTip
	Gui, 3:Destroy
Return

switchtab:
	GuiControlGet, tvar, , SysTabControl321
	GuiControlGet, tempP, 3:Pos, % (tvar=2?"候选窗口":tvar=3?"命令管理":tvar=4?"Static" (36+(YzIni["Hidden","ColorControl"]?4:0)):shurulei="pinyin"?"模糊音设置":"输入选项")
	GuiControl, 3:Move, SysTabControl321, % "h" tempPy+tempPh
	Gui, 3:Show, AutoSize
Return

Starting:
	GuiControlGet, %A_GuiControl%, 3:, %A_GuiControl%
	If Startingup {
		If A_IsCompiled
			tvar = schtasks /Create /TN "影子输入法" /TR "%A_ScriptFullPath%" /SC ONLOGON
		Else
			tvar = schtasks /Create /TN "影子输入法" /TR "%A_AhkPath% %A_ScriptFullPath%" /SC ONLOGON
		tvar .= (Adminfg?" /RL HIGHEST /F":" /F")
		Try {
			Run *RunAs cmd.exe /c %tvar%, , Hide
			YzIni.Settings["Startingup"]:=Startingup
		} Catch {
			Startingup:=0
			GuiControl, 3:, Startingup, 0
		}
	} Else {
		tvar = schtasks /Delete /TN "影子输入法" /F
		Try {
			Run *RunAs cmd.exe /c %tvar%, , Hide
			YzIni.Settings["Startingup"]:=Startingup
		} Catch {
			Startingup:=1
			GuiControl, 3:, Startingup, 1
		}
	}
Return

runasadmin:
	GuiControlGet, %A_GuiControl%, 3:, %A_GuiControl%
	If (Adminfg&&!A_IsAdmin){
		Try {
			If A_IsCompiled
				Run *RunAs "%A_ScriptFullPath%" /restart
			Else
				Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
			YzIni.Settings[A_GuiControl]:=Adminfg, YzIni.Save()
			ExitApp
		} Catch {
			Adminfg:=0
			GuiControl, 3:, Adminfg, 0
			Return
		}
	}
	YzIni.Settings[A_GuiControl]:=Adminfg
Return

ini_GuiStyle:
ini_Settings:
ini_Hotkey:
	GuiControlGet, %A_GuiControl%, 3:, %A_GuiControl%
	YzIni[SubStr(A_ThisLabel, 5), tvar:=LTrim(A_GuiControl,"_")]:=%tvar%:=%A_GuiControl%
	If (A_GuiControl="Wordfrequency"){
		GuiControl, 3:Enable%Wordfrequency%, fixedword
	} Else If (A_GuiControl~="Font|ListNum|Lockedposition"){
		Gosub houxuankuangguicreate
		If srf_all_Input
			Gosub srf_tooltip
	} Else If (A_GuiControl="Traditional"){
		If FileExist("Lib\@s2t.txt")
			valueindex:=Traditional?5:2
		Else {
			YzIni["Settings","Traditional"]:=Traditional:=0
			GuiControl, 3:, Traditional, 0
			MsgBox, 48, 提示, 简繁转换文件不存在，请在Lib目录下放置简繁转换文件@s2t.txt，格式如下：`n㐷=傌`n㐹=㑶 㐹`n㐽=偑`n码表=碼錶 碼表`n文本编码为UTF-8-Bom或ANSI
		}
	} Else If (A_GuiControl~="SendDelay|SendFromClip")
		SendDelaymode:=(SendFromClip?"{Fast" (SendDelay?"," SendDelay*10:"") "}":(SendDelay?"{Text}{Delay," SendDelay*10 ",0}":""))
	Else If (A_GuiControl="LogoSize"){
		If (!A_IsSuspended)
			Gosub SetLogoSize
	} Else If (A_GuiControl="Different"){
		GuiControl, 3:Enable%Different%, IMEmode
		SetTimer, AppImeAutoSwitch, % (Different?"150":"Off")
	} Else If (A_GuiControl="pinyinhunsu"){
		GuiControl, 3:Enable%pinyinhunsu%, ShowCode
	} Else If (A_GuiControl="ShowCode"){
		If (ShowCode&&Inputscheme~="wubi|五笔")
			DB.Exec("CREATE INDEX IF NOT EXISTS ""fc_" Inputscheme """ ON """ Inputscheme """ (""value"")")
	} Else If (A_GuiControl="ToolTipStyle")
		Gosub houxuankuangguicreate
	Else If (A_GuiControl="fuzhuma"){
		If (fuzhuma)
			Gosub ReLoadfuzhuma
		Else
			srf_fzm_fancha_table:=""
	} Else If (A_GuiControl="MemoryDB"){
		Gui, 3:+Disabled
		If (DB._Path=":memory:"&&DB.Changes){
			Suspend, On
			Progress, B2 ZH-1 ZW-1 FS12, 保存内存数据库中，请稍后...
			SaveDB(1)
			Suspend, Off
			Progress, Off
		}
		Gosub LoadDB
		Gui, 3:-Disabled
	} Else If (A_GuiControl="zigen"){
		If (zigen){
			If FileExist("Lib\@" Inputscheme ".txt")
				MsgBox, 64, 提示, 字根提示需要相关的字体，`nGitee、群文件有字体下载。
			Else {
				YzIni["Settings","zigen"]:=zigen:=0
				GuiControl, 3:, zigen, 0
				MsgBox, 16, 提示, 字根提示需要字根拆分文件@%Inputscheme%.txt，`nGitee、群文件有wubi98拆分文件下载。
			}
		}
	}
Return

surufangan:
	GuiControlGet, _Inputscheme, 3:, _Inputscheme
	If (!_Inputscheme){
		MsgBox 无该类词库，请先导入词库后重新打开选项！！
	} Else If (shurulei="pinyin"||_Inputscheme~="双拼$|全拼"){
		Inputscheme:=pinyince[_Inputscheme], YzIni.Settings["Inputscheme"]:=Inputscheme
		GuiControl, % "3:Disable" (_Inputscheme="全拼"), Showquanpin
	} Else
		YzIni.Settings["Inputscheme"]:=Inputscheme:=_Inputscheme, shurulei:=MethodTable[Inputscheme]?MethodTable[Inputscheme]:"xingma"
Return

shurulei:
	If (A_GuiControl="形码类"){
		If (Inputscheme~="pinyin|sp$"){
			tvar:=""
			For Value,Key In ["fixedword","Imagine","Learning","Wordfrequency"] {
				tvar .= YzIni["Settings",key]
				GuiControl, 3:, %key%, % (YzIni["Settings",key]:=%key%:=(SubStr(YzIni["Settings","Settingsbak"], A_Index, 1)?1:0))
			}
			tvar .= Inputscheme
			GuiControl, 3:, _Inputscheme, %xingmaleitable%
			Inputscheme:=SubStr(YzIni["Settings","Settingsbak"], 5)?SubStr(YzIni["Settings","Settingsbak"], 5):StrSplit(xingmaleitable, "|", "|")[2]
			YzIni["Settings","Settingsbak"]:=tvar
			GuiControl, 3:ChooseString, _Inputscheme, %Inputscheme%
			Loop 19
				GuiControl, % "3:Hide" (A_Index<14), % "Button" (A_Index+22)
			GuiControl, 3:Text, Imagine, 逐码提示
			GuiControl, 3:Text, Learning, 引导学习
			GuiControl, 3:Enable%pinyinhunsu%, ShowCode
			GuiControlGet, tempP, 3:Pos, 输入选项
			YzIni.Settings["Inputscheme"]:=Inputscheme
		}
		shurulei:=MethodTable[Inputscheme]?MethodTable[Inputscheme]:"xingma"
	} Else {
		shurulei:="pinyin"
		GuiControl, 3:, _Inputscheme, %pinyinlist%
		If !(Inputscheme~="pinyin|sp$"){
			tvar:=""
			For Value,Key In ["fixedword","Imagine","Learning","Wordfrequency"] {
				tvar .= YzIni["Settings",key]
				GuiControl, 3:, %key%, % (YzIni["Settings",key]:=%key%:=(SubStr(YzIni["Settings","Settingsbak"], A_Index, 1)?1:0))
			}
			tvar .= Inputscheme, Inputscheme:=SubStr(YzIni["Settings","Settingsbak"], 5)?SubStr(YzIni["Settings","Settingsbak"], 5):"pinyin"
			YzIni["Settings","Settingsbak"]:=tvar
		}
		_Inputscheme:=pinyinec[Inputscheme]
		GuiControl, 3:ChooseString, _Inputscheme, %_Inputscheme%
		GuiControl, % "3:Disable" (Inputscheme="pinyin"), Showquanpin
		Loop 19
			GuiControl, % "3:Show" (A_Index<14), % "Button" (A_Index+22)
		GuiControl, 3:Text, Imagine, 联想
		GuiControl, 3:Text, Learning, 自学习
		GuiControlGet, tempP, 3:Pos, 模糊音设置
		YzIni.Settings["Inputscheme"]:=Inputscheme
	}
	GuiControl, 3:Enable%Wordfrequency%, fixedword
	GuiControl, 3:Move, SysTabControl321, % "h" tempPy+tempPh
	Gui, 3:Show, AutoSize
Return

mohuying:
	GuiControlGet, %A_GuiControl%, 3:, %A_GuiControl%
	mhyRegExstr:=(mhy_zh?"z":"") (mhy_sh?"s":"") (mhy_ch?"c":"") (mhy_ang?"a":"") (mhy_eng?"e":"") (mhy_ing?"i":"")
	pyfenci("",""), YzIni.Settings[A_GuiControl]:=%A_GuiControl%
Return

Textdirection:
	Textdirection:=YzIni.GuiStyle["Textdirection"]:=A_GuiControl
Return

setcolor:
	Critical, Off
	Gui, 3:Default
	tempColor:="0x" YzIni.GuiStyle[A_GuiControl]
	If Dlg_Color(tempColor, HGui3){
		%A_GuiControl%:=SubStr(tempColor, 3)
		YzIni.GuiStyle[A_GuiControl]:=(StrLen(YzIni.GuiStyle[A_GuiControl])=8?SubStr(YzIni.GuiStyle[A_GuiControl],1,2):"") SubStr(tempColor, 3)
		GuiControl,, %A_GuiControl%, % SubStr(tempColor, 3)
		If (!YzIni["Hidden","ColorControl"])
			SetButtonColor(A_GuiControl, tempColor)
		Gosub houxuankuangguicreate
		If srf_all_Input
			Gosub showhouxuankuang
	}
Return

sethotkey:
	Gui 3:+OwnDialogs
	GuiControlGet, srfhotkey, 3:, srfhotkey
	If (srfhotkey=Switch)||(srfhotkey~="i)^[a-z\d,\./;'\[\]\-=]$")||!srfhotkey {
		GuiControl, 3:Text, srfhotkey, %Switch%
		Return
	} Else {
		tarr:=StrSplit(srfhotkey, "&", " ")
		Loop % tarr.Length()
		{
			If !(GetKeyVK(tarr[A_Index])||GetKeyVK(LTrim(tarr[1], "<>!^#+"))||(tarr[A_Index]~="i)^(L|R)?(Win|Alt|Shift|Control|Ctrl|CapsLock)$")) {
				GuiControl, 3:Text, srfhotkey, %Switch%
				MsgBox, 16, 错误, 热键名错误, 3
				Return
			}
		}
		Hotkey If, !(srf_inputing&&Switch~="Shift")
		Try	{
			If (Switch)
				Hotkey, %Switch%, srfSwitch, Off
			Hotkey, %srfhotkey%, srfSwitch, On
			Switch:=YzIni.Hotkey["Switch"]:=srfhotkey
			
			If !InStr(srfhotkey,"&")&&(srfhotkey~="i)(L|R)?(Win|Alt|Shift|Control|Ctrl|CapsLock)"){
				Try Hotkey, % "~" Trim(Switch,"+!#^") " & XButton2", AndLButton, Off
				Try Hotkey, % "~" Trim(srfhotkey,"+!#^") " & XButton2", AndLButton, On
			}
		} Catch {
			GuiControl, 3:Text, srfhotkey, %Switch%
			Try Hotkey, %Switch%, srfSwitch, On
			MsgBox, 16, 错误, 注册热键失败, 3
		}
		Hotkey If
	}
Return

WM_MOUSEMOVE(wParam, lParam, Msg, Hwnd){
	global TableName, HLV1
	static buf, lasthwnd:=0, lastpos:=0
		, tips:={Startingup:"此功能需要系统的任务计划服务支持",Autoupdatefg:"勾选自动更新后会检测最新版的exe文件并提示更新，并不会更新源码部分，`n源码请在Gitee、百度网盘、QQ群中下载",Adminfg:"未勾选此选项，在其他使用管理员权限运行的应用中无法使用各种功能`n勾选后，超级命令库的鼠标拖拽生成命令功能失效",chaojijp:"显示四字及以上的简拼候选",bddp:"，。首选上屏并上屏标点，与魔法字符串、超级命令选项冲突"
			,EnChar:"勾选后可在开启其他输入法中文输入状态时，`n正常上屏英文字符、标点，但无法响应相关热键",SendDelay:"部分控件无法响应太快的键击导致上屏漏字，`n适当调高延时解决相关问题",Imagine:"拼音联想后续的字词`n形码类逐码提示",MemoryDB:"将数据库载入内存获取更好的性能，关闭此选项、退出影子时保存数据库",SendFromClip:"部分界面、控件上屏异常，可以尝试开启此选项"
			,Wordfrequency:"勾选后词频随使用逐步增长，影响词条在候选中的排列顺序`n手动调频Ctrl + 0-9",Superrun:"勾选后在候选中显示超级命令库的首个命令，`n按。键可启动程序、打开文件、运行ahk脚本、切换部分设置、`n上屏内置函数返回值（可添加在自定义短语中使用）`n",Magicstring:"勾选后在候选中显示魔法字符串库的首个词条，词条可以带换行等格式，`n按，键上屏文本、以键击发送完成快速填表、粘贴大段文本"
			,Learning:"勾选后记录使用\键断词、8字以内的词组到词库`n形码``键分隔编码",Different:"勾选后每个应用有各自的中英文输入状态，切换应用时自动切换输入状态",IMEmode:"应用第一次启动时的默认输入状态。",应用管理:"设置每次切换到该应用时的输入状态",SymbolFont:"设置候选项界面输入特殊符号时的字体",MouseCross:"鼠标划词后1s内按Ctrl弹出选择菜单",dwxg:"按住空格键显示提示，上屏长词条的部分`n进入辅助码筛选模式"
			,拼音类:"包括全拼、双拼方案，共用pinyin词库",形码类:"最大码长等于4的方案，导入相应词库后生成对应选项，导入文件名即方案名",Traditional:"勾选后词条中简体字以繁体字形式显示上屏，`n不勾选时不对词条中的繁体进行处理",ShowCode:"形码类临时拼音输入时反查编码",pinyinhunsu:"Shift+z进入临时拼音模式",zigen:"显示形码的拆分，需要拆分文件"
			,Showquanpin:"显示双拼对应的全拼编码",CloudInput:"候选中插入云输入的结果，显示速度与网络速度相关`n获取失败或与本地词条重复时不显示",SaveCloud:"勾选自学习后选择云输入的候选并记录到词库`n不需要开启自学习",fuzhuma:"使用任意一或二位辅助码协助筛选候选项去除重码",TextFont:"设置候选项界面的字体",FontSize:"设置候选项字体大小",LogoSize:"设置输入状态指示图标的大小，设为0时隐藏Logo",ToolTipStyle:"设置候选界面的样式，ToolTip兼容性好速度慢，Gdip速度更快适合Win7及以上的系统"
			,Lockedposition:"固定候选界面不随光标移动，可鼠标拖动至适合位置",srfhotkey:"设置输入法中/英文状态切换热键，按键名可查阅ahk中文帮助目录/热键、索引/key list部分",Double:"勾选后双击切换输入模式，LCtrl+LAlt+F12可禁用/恢复所有热键",FuncLV:"内置函数命令，可输入命令名加/使用，可自定义设置命令名",导入词库:"导入的码表文件是以待导入的词库名为前缀的文本文档(如wubi86_1.txt;zhengma.txt)，推荐编码为UTF-8-BOM。`n每行包括编码、词条、权重或备注(非必须)，以=或Tab或空格分隔。`n导入pinyin、wubi86、wubi98词库时，编码非必须，可自动生成。各行格式一致，格式如下：`n五笔86：`naaaa=恭恭敬敬=劳斯莱斯=花花草草 （无weight）`nggtt=五笔=5`n`n拼音、双拼：`npin'yin=拼音=16`n影子输入法=20`n`nhotstrings、functions为JSON格式,换行\n Tab\t：`n[""key"",""value"",""comment""]"
			,导出词库:"导出当前词库查询后的所有词条，存放在" A_ScriptDir,删除词库:"删除当前选择的词库",整理词库:"对词库进行去重排序，保留最大权重",压缩词库:"词库在删除词条后空间没有释放，使用压缩词库释放空间",TableName:"选择相应的词库进行管理或导出`n双击对应区域进入编辑模式，进行词条修改。`n右键新建、删除词条，魔法创建可添加多个词条或创建带格式的文本`n点击右下角可设置每页显示的词条数",citiao:"精确查找输入的编码、词条、备注，_代表一位任意字符、%代表任意位字符"
			,StatusBar:"点击状态栏右下角设置每页显示词条数，PgUp、PgDn为翻页键",ResultsLV:{}}
	If !VarSetCapacity(buf)
		VarSetCapacity(buf, 20 * (A_IsUnicode ? 2 : 1))
	If (lastpos!=lParam)&&(Hwnd!=HLV1){
		ToolTip
		lastpos:=lParam
	}
	If (lasthwnd=Hwnd)
		Return
	Else
		lasthwnd:=Hwnd
	GuiControlGet, buf, Name, %Hwnd%
	If (buf="")
		DllCall("GetWindowText", "ptr", Hwnd, "str", buf, "int", 20)
	If (tips[buf])
		SetTimer, Showhelptips, -500
	Return
	Showhelptips:
	MouseGetPos, , , , poshwnd, 2
	If (tips[buf])&&(lasthwnd=poshwnd+0){
		If (buf="ResultsLV")
			ToolTip % tips[buf,TableName]
		Else
			ToolTip % tips[buf]
	}
	Return
}

ListFonts(){
	static fontlist:=""
	If (fontlist)
		Return fontlist
	VarSetCapacity(logfont, 128, 0), NumPut(1, logfont, 23, "UChar")
	obj := []
	DllCall("EnumFontFamiliesEx", "ptr", DllCall("GetDC", "ptr", 0), "ptr", &logfont, "ptr", RegisterCallback("EnumFontProc"), "ptr", &obj, "uint", 0)
	For font in obj
		fontlist .= "|" font
	fontlist:=LTrim(fontlist,"|")
	Return fontlist
}
EnumFontProc(lpFont, tm, TextFont, lParam){
	obj := Object(lParam)
	If (TextFont>1&&!InStr(font:=StrGet(lpFont+28), "@"))
		obj[font] := 1
	Return 1
}
/* Title:	Dlg
			*Common Operating System Dialogs*
 */

/*
 Function:		Color
				(See Dlg_color.png)

 Parameters: 
				Color	- Initial color and output in RGB format.
				hGui	- Optional handle to parents Gui. Affects dialog position.
  
 Returns:	
				False if user canceled the dialog or if error occurred	
 */ 
Dlg_Color(ByRef r_Color, hOwner:=0){
    Static CHOOSECOLOR, s_CustomColors
    if !VarSetCapacity(s_CustomColors){
        VarSetCapacity(s_CustomColors,64,0)
		; CustomColors:=[0x99731C,0xECEEEE,0x8B4E01,0x444444,0xE89F00,0x70B33E,0x2DB6F8,0x81A300
		; 			,0xD77800,0x0A1B0D,0x97D4B9,0xEFAD00,0xBF7817,0xE3F6FD,0x362B00,0xDEDEDE]
		CustomColors:=[0xE9E5D9,0x0B0A13,0xFBF2E0,0xECF0E8,0xA5F0D1,0xADC9D9,0xE2ECF9,0x0C0C0C
					,0x99731C,0xECEEEE,0x8B4E01,0x559311,0x0A1B0D,0x444444,0x362B00,0xDEDEDE]
		Loop % CustomColors.Length()
			NumPut(CustomColors[A_Index], s_CustomColors, 4*(A_Index-1), "UInt")
	}
    l_Color:=r_Color, l_Color:=((l_Color&0xFF)<<16)+(l_Color&0xFF00)+((l_Color>>16)&0xFF)

    ;-- Create and populate CHOOSECOLOR structure
    lStructSize:=VarSetCapacity(CHOOSECOLOR,(A_PtrSize=8) ? 72:36,0)
    NumPut(lStructSize,CHOOSECOLOR,0,"UInt")            ;-- lStructSize
    NumPut(hOwner,CHOOSECOLOR,(A_PtrSize=8) ? 8:4,"Ptr")
        ;-- hwndOwner
    NumPut(l_Color,CHOOSECOLOR,(A_PtrSize=8) ? 24:12,"UInt")
        ;-- rgbResult
    NumPut(&s_CustomColors,CHOOSECOLOR,(A_PtrSize=8) ? 32:16,"Ptr")
        ;-- lpCustColors
    NumPut(0x00000103,CHOOSECOLOR,(A_PtrSize=8) ? 40:20,"UInt")
        ;-- Flags
    RC:=DllCall("comdlg32\ChooseColor" . (A_IsUnicode ? "W":"A"),"Ptr",&CHOOSECOLOR)

    ;-- Cancelled? (user pressed the "Cancel" button or closed the dialog)
    if (RC=0)
        Return False
    ;-- Collect the selected color
    l_Color:=NumGet(CHOOSECOLOR,(A_PtrSize=8) ? 24:12,"UInt")
        ;-- rgbResult
    ;-- Convert to RGB
    l_Color:=((l_Color&0xFF)<<16)+(l_Color&0xFF00)+((l_Color>>16)&0xFF)

    ;-- Update r_Color with the selected color
    r_Color:=Format("0x{:06X}",l_Color)
    Return True
}
SetButtonColor(ControlID, Color, Margins:=5){
	GuiControlGet, hwnd, 3:Hwnd, %ControlID%
	VarSetCapacity(RECT, 16, 0), DllCall("User32.dll\GetClientRect", "Ptr", hwnd, "Ptr", &RECT)
	W := NumGet(RECT, 8, "Int") - (Margins * 2), H := NumGet(RECT, 12, "Int") - (Margins * 2)

	Color:=((Color&0xFF)<<16)+(Color&0xFF00)+((Color>>16)&0xFF)
	hbm:=CreateDIBSection(W, H), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
	hBrush:=DllCall("CreateSolidBrush", "UInt", Color, "UPtr"), obh:=SelectObject(hdc, hBrush)
	DllCall("Rectangle", "UPtr", hdc, "Int", 0, "Int", 0, "Int", W, "Int", H), SelectObject(hdc, obm)
	BUTTON_IMAGELIST_ALIGN_CENTER := 4, BS_BITMAP := 0x0080, BCM_SETIMAGELIST := 0x1602, BITSPIXEL := 0xC
	BPP := DllCall("Gdi32.dll\GetDeviceCaps", "Ptr", hdc, "Int", BITSPIXEL)
	HIL := DllCall("Comctl32.dll\ImageList_Create", "UInt", W, "UInt", H, "UInt", BPP, "Int", 6, "Int", 0, "Ptr")
	DllCall("Comctl32.dll\ImageList_Add", "Ptr", HIL, "Ptr", hbm, "Ptr", 0)
	; ; Create a BUTTON_IMAGELIST structure
	VarSetCapacity(BIL, 20 + A_PtrSize, 0), NumPut(HIL, BIL, 0, "Ptr")
	Numput(BUTTON_IMAGELIST_ALIGN_CENTER, BIL, A_PtrSize + 16, "UInt")
	SendMessage, BCM_SETIMAGELIST, 0, 0, , ahk_id %HWND%
	SendMessage, BCM_SETIMAGELIST, 0, &BIL, , ahk_id %HWND%
	SelectObject(hdc, obm), SelectObject(hdc, obh), DeleteObject(hbm), DeleteObject(hBrush), DeleteDC(hdc)
}
WM_CTLCOLORSTATIC(wParam, lParam, msg, hwnd){
	Critical
	static brushes := []
	Gui +OwnDialogs
	If (!hwnd){
		For _,brush In brushes
			If (brush)
				DllCall("DeleteObject", "ptr", brush)
		brushes := []
		Return
	}
	GuiControlGet varName, Name, %lParam%
	If !InStr(varName, "Color")
		Return
	If (brush := brushes[lParam]) && brush >= 0
		DllCall("DeleteObject", "ptr", brush)
	GuiControlGet tt,, %varName%
	clr:="0x" tt, clr:=(clr & 0xFF00) | (clr >> 16) | ((clr&0xFF)<<16)
	brushes[lParam] := brush := DllCall("CreateSolidBrush", "uint", clr, "ptr")
	DllCall("SetBkMode", "uint", wParam, "int", 1)
	DllCall("SetTextColor", "uint", wParam, "int", ~clr&0xffffff)
	DllCall("SetBkColor", "uint", wParam, "int", clr)
	Return brush
}